/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package expression;

import core.Node;
import core.UnsatException;
import domain.Domain;

/**
 *
 * @author ddoose
 */
public class Alias extends IntExpr {
    private String name;
    
    public Alias(Node n, String s) {
        super(n);
        name = s;
        current = Domain.UNIVERSE;
        target = Domain.UNIVERSE;
    }
    
    public Alias(Node n, String s, IntExpr i) {
        super(n, i);
        name = s;
        current = Domain.UNIVERSE;
        target = Domain.UNIVERSE;
    }
    
    public String getName() {
        return name;
    }

    public boolean same(IntExpr i) {
        return (i instanceof Alias) && name.equals(((Alias)i).getName()) && sameParameters(i);
    }
    
    public void propagate() throws UnsatException {
        node.addPropagation(getParameters().get(0));
    }
    
    public void eval() throws UnsatException {
        IntExpr e = node.getIntExpr(getParameters().get(0));
        reduceCurrent(e.current);
    }
    
    public boolean reduce() {
        node.removeIntExpr(this);
        return true;
    }

    public Alias clone(Node node) {
        Alias alias = new Alias(node, name);
        alias.clone(this);
        return alias;
    }
    
    public String toString() {
        return name;
    }
    
    public String pretty() {
        return name + " : " + current + " " + target;
    }
}
